package xyz.erupt.flow.core.engine.formItems.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.erupt.flow.bean.entity.form.FormComponent;
import xyz.erupt.flow.core.engine.Utils.BeanUtil;
import xyz.erupt.flow.core.engine.formItems.WorkFlowFormItemService;
import xyz.erupt.flow.core.engine.formItems.vo.FormItemFieldVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author PP
 * @version 1.0
 * @project flow
 * @description 分栏实现
 * @date 2024/10/29 10:08:37
 */
@Service("SpanLayout")
public class SpanLayoutImpl implements WorkFlowFormItemService {
    @Autowired
    private BeanUtil beanUtil;
    @Override
    public List<FormItemFieldVo> generateFormItemFieldVoList(FormComponent formComponent) {
        ArrayList<FormItemFieldVo> fieldVos = new ArrayList<>();
        //将分栏中的所有数据查询出来，去除分栏，创建多个字段
        List<FormComponent> allItemFieldsBySpanLayout = formComponent.findAllItemFieldsBySpanLayout();
        if(!allItemFieldsBySpanLayout.isEmpty()){
            allItemFieldsBySpanLayout.forEach(itemField -> {
                WorkFlowFormItemService beanByName = beanUtil.getBeanByName(itemField.getName(), WorkFlowFormItemService.class);//调用各个实现类来构建传回类
                List<FormItemFieldVo> formItemFieldVos = beanByName.generateFormItemFieldVoList(itemField);
                fieldVos.addAll(formItemFieldVos);
            });
        }
        return fieldVos;
    }
}
